package com.example.dataservice.service;

import com.example.api.pojo.BaseInfo;
import com.example.api.service.PlatBaseInfoService;
import com.example.dataservice.mapper.BidInfoMapper;
import com.example.dataservice.mapper.ProductMapper;
import com.example.dataservice.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Author cjk
 * @Date 2024 07 23 19 35
 **/
@DubboService(interfaceClass = PlatBaseInfoService.class,version = "1.0")
public class PlatBaseInfoServiceImpl implements PlatBaseInfoService {
    //注入mapper

    @Resource
    private UserMapper userMapper;

    @Resource
    private ProductMapper productMapper;

    @Resource
    private BidInfoMapper bidInfoMapper;


    /** 平台基本信息 */
    @Override
    public BaseInfo queryPlatBaseInfo() {

        //获取注册人数 收益率平均值  累计成交金额
        //获取注册人数
        int registerUsers = userMapper.selectCountUser();
        //收益率平均值
        BigDecimal historyAvgRate = productMapper.selectAvgRate();
        //累计成交金额
        BigDecimal sumBidMoney = bidInfoMapper.selectSumBidMoney();

        BaseInfo baseInfo = new BaseInfo(historyAvgRate, sumBidMoney, registerUsers);
        return baseInfo;
    }
}
